﻿using System;
using System.Collections.Generic;
using System.Text;
using ProcessControl.Interface;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Configuration;
using System.IO;
using ProcessControl.Entity;

namespace ProcessControl.Logic
{
    public class POLogic : IPO
    {
        private DataHelper db = new DataHelper();
        public string flag = DataHelper.ParameterFlag;   

        /// <summary>
        /// 更新PO的行数据状态（0为初始值，1为已经提交审批过的）
        /// </summary>
        /// <param name="MaterialName"></param>
        /// <param name="FormID"></param>
        /// <returns></returns>
        public bool UpdateRowsStatus(string MaterialName, string FormID)
        {
            bool IsSuccess = false;
            try
            {              
                StringBuilder strsql = new StringBuilder();
                strsql.Append("update dbo.PROC_PO_DT set STATUS=1 where FORMID='" + FormID.Trim() + "' and  MATERIALNAME='" + MaterialName.Trim() + "'");
                DbCommand dbcom = db.GetSqlStringCommond(strsql.ToString());                 
                DataTable dt = db.ExecuteDataTable(dbcom);
                IsSuccess = true;
                
            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }
            return IsSuccess;
        }

        /// <summary>
        /// 更新PO的行数据的已使用数量
        /// </summary>
        /// <param name="MaterialName"></param>
        /// <param name="FormID"></param>
        /// <returns></returns>
        public bool UpdateRowsUsedQty(string MaterialName, string FormID, int UsedQty)
        {
            bool IsSuccess = false;
            try
            {
                StringBuilder strsql = new StringBuilder();
                strsql.Append("update dbo.PROC_PO_DT set USEDORDERS='" + UsedQty.ToString().Trim() + "' where FORMID='" + FormID.Trim() + "' and  MATERIALNAME='" + MaterialName.Trim() + "'  ");
                DbCommand dbcom = db.GetSqlStringCommond(strsql.ToString());
                DataTable dt = db.ExecuteDataTable(dbcom);
                IsSuccess = true;

            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }
            return IsSuccess;
        }
    }
}
